package com.no.seckill.service.Impl;

import com.no.seckill.common.BusinessException;
import com.no.seckill.common.ErrorCode;
import com.no.seckill.dao.UserMapper;
import com.no.seckill.entity.User;
import com.no.seckill.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhang kun
 * @Classname UserServiceImpl
 * @Description TODO
 * @Date 2021/8/31 21:10
 */
@Service
public class UserServiceImpl implements UserService, ErrorCode {

    @Autowired(required = false)
    private UserMapper userMapper;

    @Override
    public User login(String username, String password) {
        if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
            throw new BusinessException(PARAMETER_ERROR, "参数不合法！");
        }

        User user = userMapper.selectByName(username);
        if (user == null || !StringUtils.equals(password, user.getPassword())) {
            return null;
        }
        return user;
    }

    @Override
    public User findUserById(String username) {
        return null;
    }
}
